package server;

import java.sql.SQLException;
import capsules.CapsuleSpecification;
import database.DatabaseOperationsCapsules;

public  class Replicator {


	private DatabaseOperationsCapsules dbOpCapsules;
	private Boolean accessSynchronized;


	public Replicator(DatabaseOperationsCapsules dbOpCapsules){
		this.dbOpCapsules = dbOpCapsules;
		this.accessSynchronized = new Boolean(true);
	}


	public CapsuleSpecification getCapsuleSpecification()
            throws SQLException{
		synchronized (accessSynchronized) {
			CapsuleSpecification capsuleSpecification = dbOpCapsules.getCapsuleForReplication();

			dbOpCapsules.setCapsuleReplicated(capsuleSpecification.getName());

			return capsuleSpecification;
		}
	}


	public void close()
            throws SQLException{
		synchronized (accessSynchronized) {
			if(dbOpCapsules!=null){
				dbOpCapsules.close();
				dbOpCapsules = null;
			}
		}
	}


}
